package com.itheima.excel.service.impl;

import com.alibaba.excel.EasyExcel;
import com.itheima.excel.entity.User;
import com.itheima.excel.listener.DemoDataListener;
import com.itheima.excel.mapper.UserMapper;
import com.itheima.excel.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Collection;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    @Transactional
    public void read(MultipartFile file) {
        try {
            EasyExcel.read(file.getInputStream(), User.class, new DemoDataListener(userMapper)).sheet().doRead();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public Collection<?> list() {
        return userMapper.list();
    }
}
